package com.pdg.mcplugin.simpleconomy.dataproviders.banks;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.pdg.mcplugin.common.interfaces.TableProviderValue;

public class BankValue implements TableProviderValue<BankValue>{

	public static final String FIELD_AMOUNT = "amount";
	private static final String CREATE_FIELDS = "`"+FIELD_AMOUNT+"` REAL NOT NULL";
	private static final String INSERT_FIELDS = "`"+FIELD_AMOUNT+"`";
	private static final String INSERT_VALUES = "'%s',%f";
	private static final String SELECT_LIST = "`"+FIELD_AMOUNT+"`";
	private static final String UPDATE_LIST = "`"+FIELD_AMOUNT+"`=%f";
	private static final double DEFAULT_VALUE = 0;
	private double amount;
	
	public BankValue(double theAmount){
		setAmount(theAmount);
	}

	@Override
	public String getCreateFields() {
		return CREATE_FIELDS;
	}

	@Override
	public String getInsertFields() {
		return INSERT_FIELDS;
	}

	@Override
	public String getInsertValues() {
		return String.format(INSERT_VALUES, getAmount());
	}

	@Override
	public String getSelectList() {
		return SELECT_LIST;
	}

	@Override
	public String getUpdateList() {
		return String.format(UPDATE_LIST, getAmount());
	}

	@Override
	public BankValue createValueFromResultSet(ResultSet theResultSet) {
		try {
			double theAmount = theResultSet.getDouble(FIELD_AMOUNT);
			return new BankValue(theAmount);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}
	public static BankValue defaultInstance(){
		return new BankValue(DEFAULT_VALUE);
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}
}
